package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.common.dto.HotItemDto;
import com.hdax.dm.entity.item.DmItem;
import com.hdax.dm.mappers.DmItemMapper;

import com.hdax.dm.mapstructs.HotItemDtoMapper;
import com.hdax.dm.service.DmItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DmItemServiceImpl extends ServiceImpl<DmItemMapper, DmItem> implements DmItemService {



    @Autowired
    private HotItemDtoMapper hotItemDtoMapper;

    @Override
    public List<HotItemDto> hotItemList(Long itemTypeId) {

        //封装查询条件
        QueryWrapper<DmItem> wrapper=new QueryWrapper<>();
        wrapper.eq("isRecommend",1);
        //类别的id
        wrapper.eq("itemType1Id",itemTypeId);
        //排序
        //根据平均分排序
        wrapper.orderByAsc("avgScore");
        //开始演出时间进行排序
        wrapper.orderByAsc("startTime");
        //分页处理默认查询五条数据
        IPage<DmItem> page= Page.of(1,5);

        List<HotItemDto> hotItemDtoList = hotItemDtoMapper.toTargerList(page.getRecords());
        return hotItemDtoList;
    }

    @Override
    public List<HotItemDto> hotItems(Long itemTypeid) {
        List<DmItem> dmItems = baseMapper.selDmItemByTypeId(itemTypeid);
        List<HotItemDto> hotItemDtos = hotItemDtoMapper.toTargerList(dmItems);
        return hotItemDtos;
    }


}
